package com.chif.goingplus.controller;

import com.chif.goingplus.pojo.Destination;
import com.chif.goingplus.service.DestinationService;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/destination")
public class DestinationController {


    @Autowired
    DestinationService destinationService;

    @RequestMapping("/queryAll")
    public String getOrigin(){
        List<Destination> destinations = destinationService.queryAllDestination();
        return JsonUtils.getJson(destinations);
    }


    @RequestMapping("/add")
    public String addDestination(Destination destination){
        destinationService.addDestination(destination);
        return destination.getDeid()+"新增目的地成功";
    }


    @RequestMapping("/update")
    public String update(Destination Destination){
        destinationService.updateDestination(Destination);
        return "修改地点信息成功";
    }


    @RequestMapping("/delete")
    public String delete(int id){
        destinationService.deleteDestinationById(id);
        return "删除地点信息成功";
    }
}
